﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class DayToDayManagement_CMDDOWN : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSMThemes();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        Check.CheckPermission("300100104");
        if (!IsPostBack)
        {
            AspNetPager1.PageSize = Convert.ToInt32(ConfigurationManager.AppSettings["RowCountPerPage"].ToString());
            ((Button)BUTTONDJLIST1.Controls[4]).Enabled = false;
            ((Button)BUTTONDJLIST1.Controls[6]).Enabled = false;
            BindDropDownType();
            Bind();
        }
    }

    private void BindDropDownType()
    {
        List<Model.DOWNTYPE> properties = new BLL.DOWNTYPE().GetAllList();
        dropType.DataSource = properties;
        dropType.DataTextField = "DT_NAME";
        dropType.DataValueField = "DT_CODE";
        dropType.DataBind();
        ListItem li = new ListItem();
        li.Text = " ";
        li.Value = "-1";
        dropType.Items.Insert(0, li);
    }

    private void Bind()
    {
        string sqlstr = "";
        sqlstr += txtCode.Text.Trim() == "" ? "" : " and cd_id='" + txtCode.Text.Trim() + "' ";
        sqlstr += dropType.SelectedValue.Trim() == "-1" ? "" : " and cd_downtype='" + dropType.SelectedValue + "' ";
        sqlstr += dropCheck.SelectedValue == "-1" ? "" : " and cd_check=" + dropCheck.SelectedValue + " ";
        sqlstr += txtDate.Text.Trim() == "" ? "" : " and cd_downdate<='" + txtDate.Text.Trim() + "' ";
        int pageCount, rowCount;
        List<Model.CMDDOWN> properties = new BLL.CMDDOWN().GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, "cd_downdate", true, sqlstr, out pageCount, out rowCount);
        CMDDOWNListControl1.Bind(properties);
        AspNetPager1.RecordCount = rowCount;
    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        Bind();
    }
    public void Add()
    {
        if (Check.CheckPermission("300100104", "00001"))
        {
            Response.Redirect("CMDDOWNEDIT.aspx");
        }
        else
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
    }
    public void Update()
    {
        if (Check.CheckPermission("300100104", "00002"))
        {
            List<string> s = CMDDOWNListControl1.Selected;
            if (s.Count > 0)
            {
                Response.Redirect("CMDDOWNEDIT.aspx?code=" + s[0]);
            }
            else
            {
                Share.Alert(this.Page, "请选择一条需要编辑的记录"); return;
            }
        }
        else
        {
            Share.Alert(this.Page, "无权操作"); return;
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        Bind();
    }
}
